#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "inst.h"

int main( int argc, char **argv )
{
	struct stage2 bhw;
	int len, fd, i;
	char label[32], *lab;

	fd = open( "/boot/bhw2", O_RDONLY);
	len = read( fd, &bhw, 512);
	close(fd);

	for ( i = 0; i < 4; i++ ) 
	{
    	    printf ( "/dev/hda%d label: ", i+1 );
	    scanf ( "%s", label );
	    if ( strlen( label ) == 0 || strlen( label ) > 10 )
		continue;
		
	    lab = bhw.lab1 + ( i * sizeof( bhw.lab1 ) );

	    sprintf( lab, "%d %s\n\r", i+1, label );

	}
	    
	
	if ( ( fd = open( "/boot/bhw2", O_WRONLY) ) == -1 ) {
	    printf ( "Error opening /boot/bhw2\n" );
	    exit(1);
	}
	
	if ( ( len = write( fd, &bhw, 512) ) == 0 ) {
	    printf ( "Error writing /boot/bhw2\n" );
	    exit(1);
	}
	
//	fsync(fd);
	close(fd);
	    
	sync();

	return 0;
}
